package stats;

import java.util.ArrayList;

public class Equips {
	String name = "";
	int pDef, mDef, weight, rank, enchantment = 0;
	int level = 1;
	int movSpd, maxWTInc = 0;
	int pAtk, mAtk, atkSpd = 0;
	int mpRec, hpRec, criPow = 0;
	int maxMP, maxHP, str, vit, dex, agi, intel, wis, luck = 0;
	float criChance, magRes, blockRate = 0;
	Object equipType;
	String worn;
	//TODO Implement flag Stoneable.
	
	ArrayList<Stone> stones = new ArrayList<Stone>();
	
	public class Stone{
		String type;
		int value;
		Stone(String type, int value){
			this.type = type;
			this.value = value;
		}
		public String toString(){
			String s = String.format("%s %s", type, value);
			return s;
		}
	}
	
	public String type(){
		return equipType.toString();
	}
	
	public String name(){
		return name;
	}
	
	public int getLevel(){
		return level;
	}
	
	public void setLevel(int newLevel){
		level = newLevel;
	}
	
	public int getEnchantment(){
		return enchantment;
	}
	
	public void setEnchantment(int newEnchant){
		enchantment = newEnchant;
	}
	
	public String givenStats(){
		return "0";
	}
	
	
	private void addValue(String type, int value){
		
		String stat = type.toLowerCase();
		
		if (stat.equals("vit")){
			vit += value;
		}
		else if (stat.equals("str")){
			str += value;
		}
		else if (stat.equals("dex")){
			dex += value;
		}
		else if (stat.equals("agi")){
			agi += value;
		}
		else if (stat.equals("intel")){
			intel += value;
		}
		else if (stat.equals("wis")){
			wis += value;
		}
		else if (stat.equals("luck")){
			luck += value;
		}
		
	}
	
	
	public void addStones(String type, int value, int pos){
		
		if(stones.size()<= 0){
			stones.add(new Stone(type, value));
		}else if (stones.size()>= pos){
			addValue(stones.get(pos).type, stones.get(pos).value*(-1));
			stones.set(pos, (new Stone(type, value)));
		} else {
			int i = 0;
			while(i<pos){
				stones.add(new Stone("vit", 0));
				i++;
			}
			stones.add(new Stone(type, value));
		}
		addValue(type, value);
	}

	public String stoneStats(){
		String s = "";
		for (Stone st: stones){
			s = s.concat(" "+st.toString()+";");
		}
		return s;
	}
}
	
	class Armor extends Equips{
		
		Armor(stats.CharStat.EnumArmor armor, String name, int rank, int wt, int level, int enchantment, int pd, int md){
			this.name = name;
			this.rank = rank;
			this.level = level;
			this.enchantment = enchantment;
			this.pDef = pd;
			this.mDef = md;
			this.weight = wt;
			this.movSpd = 0;
			this.equipType = armor;
			this.worn = "Armor";
			toWare();
		}
	
		Armor(stats.CharStat.EnumArmor armor, String name, int rank, int wt, int level, int enchantment, int pd, int md, int mvs){
			this.name = name;
			this.rank = rank;
			this.level = level;
			this.enchantment = enchantment;
			this.pDef = pd;
			this.mDef = md;
			this.weight = wt;
			this.movSpd = mvs;
			this.equipType = armor;
			toWare();
		}
		
		private void toWare(){
			String name = equipType.toString();
			if(name.equals("Helmet")){
				this.worn = "Head";
			} else if (name.equals("Gloves")){
				this.worn = "Hand";
			} else if (name.equals("Boots")){
				this.worn = "Feet";
			} else if (name.equals("Cloak")){
				this.worn = "Cloak";
			} else {
				this.worn = "Armor";
			}
		}
		
		public String givenStats(){
			StringBuilder result = new StringBuilder();
			String k = String.format("equipType %s; name %s, rank %s, weight %s, level %s, enchantment %s; pDef %s; mDef %s; movSpd %s;", equipType.toString(), name, rank, weight, level, enchantment, pDef, mDef, movSpd);
			result.append(k+stoneStats());
			return result.toString();
		}
	}
	
	class Weapon1h extends Equips{
		
		Weapon1h(stats.CharStat.EnumWeapons weapon, String name, int rank, int wtt, int level, int enchantment, int pAtk, int mAtk, int atkSpd){
			this.name = name;
			this.rank = rank;
			this.level = level;
			this.enchantment = enchantment;
			this.pAtk = pAtk;
			this.mAtk = mAtk;
			this.atkSpd = atkSpd;
			this.weight = wtt;
			this.equipType = weapon;
			this.worn = "Weapon";
		}
		public String givenStats(){
			StringBuilder result = new StringBuilder();
			String k = String.format("equipType %s; name %s; rank %s; weight %s; level %s; enchantment %s; pAtk %s; mAtk %s; atkSpd %s;", equipType.toString(), name, rank, weight, level, enchantment, pAtk, mAtk, atkSpd);
			result.append(k+stoneStats());
			return result.toString();
		}
	}
	
	class Weapon2h extends Equips{
		
		Weapon2h(stats.CharStat.EnumWeapons weapon, String name, int rank, int wtt, int level, int enchantment, int pAtk, int mAtk, int atkSpd){
			this.name = name;
			this.rank = rank;
			this.level = level;
			this.enchantment = enchantment;
			this.pAtk = pAtk;
			this.mAtk = mAtk;
			this.atkSpd = atkSpd;
			this.weight = wtt;
			this.equipType = weapon;
			this.worn = "Weapon";
		}
		
		public String givenStats(){
			StringBuilder result = new StringBuilder();
			String k = String.format("equipType %s; name %s; rank %s; weight %s; level %s; enchantment %s; pAtk %s; mAtk %s; atkSpd %s;", equipType.toString(), name, rank, weight, level, enchantment, pAtk, mAtk, atkSpd);
			result.append(k+stoneStats());
			return result.toString();
		}
	}
	class Accessories extends Equips{
		
		//necklace
		Accessories(stats.CharStat.EnumAccessories acc, String name, int rank, int wtt, int level, int mDef, int hpRec, int mpRec){
			this.name = name;
			this.rank = rank;
			this.level = level;			
			this.mDef = mDef;
			this.hpRec = hpRec;
			this.mpRec = mpRec;
			this.weight = wtt;
			this.equipType = acc;
			this.worn = "Necklace";
		}
		
		//earrings
		Accessories(stats.CharStat.EnumAccessories acc, String name, int rank, int wtt, int pAtk, int mAtk, int pDef, float criChance, int criPow, float magRes){
			this.name = name;
			this.rank = rank;
			this.pAtk = pAtk;
			this.mAtk = mAtk;
			this.pDef = pDef;
			this.criChance = criChance;
			this.criPow = criPow;
			this.magRes = magRes;
			this.weight = wtt;
			this.equipType = acc;
			this.worn = "Earring";
		}
		
		//rings
		Accessories(stats.CharStat.EnumAccessories acc, String name, int rank, int wtt, int maxHP, int maxMP, int str, int vit, int dex, int agi, int intel, int wis, int luck){
			this.name = name;
			this.rank = rank;
			this.maxHP = maxHP;
			this.maxMP = maxMP;
			this.str = str;
			this.vit = vit;
			this.dex = dex;
			this.agi = agi;
			this.intel = intel;
			this.wis = wis;
			this.luck = luck;
			this.weight = wtt;
			this.equipType = acc;
			this.worn = "Ring";
		}

		//Bag
		Accessories(stats.CharStat.EnumAccessories acc, String name, int rank, int weight, int addWeight){
			this.name = name;
			this.rank = rank;
			this.maxWTInc = addWeight;
			this.weight = weight;
			this.equipType = acc;
			this.worn = "Bag";
		}

		//Belt
		Accessories(stats.CharStat.EnumAccessories acc, String name, int rank, int level, int weight, int pDef, int addWeight){
			this.name = name;
			this.rank = rank;
			this.level = level;
			this.pDef = pDef;
			this.maxWTInc = addWeight;
			this.weight = weight;
			this.equipType = acc;
			this.worn = "Belt";
		}
		
		private String statNecklace(){
			StringBuilder result = new StringBuilder();
			String k = String.format("equipType %s; name %s; rank %s; weight %s; level %s; mDef %s; hpRec %s; mpRec %s;", 
					equipType.toString(), name, rank, weight, level, mDef, hpRec, mpRec);
			result.append(k);
			return result.toString();
		}
		
		private String statRing(){
			StringBuilder result = new StringBuilder();
			String k = String.format("equipType %s; name %s; rank %s; weight %s; maxHP %s; maxMP %s; str %s; vit %s; dex %s; agi %s; intel %s; wis %s; luck %s;", 
					equipType.toString(), name, rank, weight, maxHP, maxMP, str, vit, dex, agi, intel, wis, luck);
			result.append(k);
			return result.toString();
		}
		
		private String statEarring(){
			StringBuilder result = new StringBuilder();
			String k = String.format("equipType %s; name %s; rank %s; weight %s; pAtk %s; mAtk %s; pDef %s; mDef %s; criChance %s; criPow %s; magRes %s;", 
					equipType.toString(), name, rank, weight, pAtk, mAtk, pDef, mDef, criChance, criPow, magRes);
			result.append(k);
			return result.toString();
		}
		
		private String statBag(){
			StringBuilder result = new StringBuilder();
			String k = String.format("equipType %s; name %s; rank %s; weight %s; maxWeightInc %s;", 
					equipType.toString(), name, rank, weight, maxWTInc);
			result.append(k);
			return result.toString();
		}
		
		private String statBelt(){
			StringBuilder result = new StringBuilder();
			String k = String.format("equipType %s; name %s; rank %s; weight %s; level %s; pDef %s; maxWeightInc %s;", 
					equipType.toString(), name, rank, weight, level, pDef, maxWTInc);
			result.append(k);
			return result.toString();
		}
		
		public String givenStats(){
			
			if (this.equipType.toString().equals("Necklace")){
				return statNecklace();
			} else if (this.equipType.toString().equals("Earring")){
				return statEarring();
			} else if (this.equipType.toString().equals("Ring")){
				return statRing();
			} else if (this.equipType.toString().equals("Bag")){
				return statBag();
			} else if (this.equipType.toString().equals("Belt")){
				return statBelt();
			}
			return "";
		}
	}